import tkinter as tk
# 2021-06-23 11:06 by 炸天帮成员
#   用于将菜单嵌套

class create_new_frame():
    def __init__(self,root_id):
        self.parent_root = root_id
        self.create_menu()

    def create_menu(self):
        self.frame = tk.Frame(self.parent_root)
        self.frame.pack()
        # MainMenu
        self.mainmenu = tk.Menu(self.frame)
        # MainMenu-"File"
        self.filemenu = tk.Menu(self.mainmenu, tearoff = 0)
        self.filemenu.add_command(label = "Open",command = lambda :print("This is Open!"))
        self.filemenu.add_command(label = "Save",command = lambda :print("This is Save!"))
        self.filemenu.add_separator()   #   添加一条分割线
        self.filemenu.add_command(label = "Exit",command = self.parent_root.destroy)
        self.mainmenu.add_cascade(label = "File",menu = self.filemenu)
        # MainMenu-"Tools"
        self.toolmenu = tk.Menu(self.mainmenu, tearoff = 0)
        self.toolmenu.add_command(label = "Find",command = lambda :print("This is Find!"))
        self.toolmenu.add_command(label = "Debugger",command = lambda :print("This is Debugger!"))
        self.toolmenu.add_command(label = "Replace",command = lambda :print("This is Replace!"))
        self.mainmenu.add_cascade(label = "Tools",menu = self.toolmenu)
        # MainMenu-"Help"
        self.helpmenu = tk.Menu(self.mainmenu, tearoff = 0)
        self.helpmenu.add_command(label = "Documentation",command = lambda :print("This is Doc!"))
        # 将helpmenu嵌套入mainmenu
        self.mainmenu.add_cascade(label = "Help",menu = self.helpmenu)

        # MainMenu->"HanHan_Menu"->"wura_SubMenu"->"wura0"+"wura1"
        self.HanHan_Menu = tk.Menu(self.mainmenu,tearoff=0)
        self.wura_SubMenu = tk.Menu(self.HanHan_Menu,tearoff=0)
        self.wura_SubMenu.add_command(label= "wura0",command=lambda :print("This is wura0!"))
        self.wura_SubMenu.add_command(label= "wura1",command=lambda :print("This is wura1!"))
        # 将wura_SubMenu嵌套入HanHan_Menu
        self.HanHan_Menu.add_cascade(label = "wura",menu = self.wura_SubMenu)    #   Used to introduce hierarchy into the Menu.即用于嵌套Menu
        # 将HanHan_Menu嵌套入mainmenu
        self.mainmenu.add_cascade(label = "HanHan_Menu",menu = self.HanHan_Menu)

        self.parent_root.config(menu = self.mainmenu)

if __name__ == "__main__":
    root0 = tk.Tk()
    root0.geometry("400x400")

    frame_in_window_0 = create_new_frame(root0)

    root0.mainloop()